package com.example.mall.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.mall.Mapper.ProductMapper;
import com.example.mall.entity.Product;
import com.example.mall.param.brands.FindByBrandsIdParam;
import com.example.mall.param.product.AddProductParam;
import com.example.mall.param.product.DeleteProductParam;
import com.example.mall.param.product.EditProductStatusParam;
import com.example.mall.param.product.ProductTypeParam;
import com.example.mall.service.ProductService;
import com.example.mall.vo.TypeByProductVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * @author ：Dongdequan
 * @date ：Created in 2022/8/6 8:44
 * @modified By：
 */

@Service
public  class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements ProductService {

    @Autowired
    private ProductMapper productMapper;

    @Override
    public List<Product> allList() {
        QueryWrapper<Product> queryWrapper = new QueryWrapper<>();
        //queryWrapper.eq()
        return productMapper.selectList(queryWrapper);
    }

    @Override
    public HashMap typeByProductList(ProductTypeParam param) {
        Integer pageNo = param.getPageNo();
        Integer pageSize = param.getPageSize();
        IPage<TypeByProductVo> page = new Page<>(pageNo, pageSize);
        List<TypeByProductVo> vo = productMapper.productListByTypeName(page,param);
        HashMap hashMap = new HashMap();
        hashMap.put("list",vo);
        hashMap.put("size",page.getTotal());
        return hashMap;
    }

    @Override
    public Object deleteProduct(DeleteProductParam param) {
        //Product product = productMapper.selectById(param.getId());
        Product product = new Product();
        product.setId(param.getId());
        product.setStatus(3);
        return productMapper.deleteById(product);
    }

    @Override
    public Object editProductStatus(EditProductStatusParam param) {
        Product product = new Product();
        product.setId(param.getId());
        product.setStatus(param.getStatus());
        return productMapper.deleteById(product);
    }

    @Override
    public Integer addProduct(AddProductParam param) {
        Product product = new Product();
        product.setTypeId(param.getTypeId());
        product.setName(param.getName());
        product.setSellPoint(param.getSellPoint());
        product.setPrice(param.getPrice());
        product.setImage(param.getImage());
        //product.setCreatedUser();
        product.setStatus(1);
        product.setPriority(param.getPriority());
        product.setCreatedTime(new Date());
        product.setBrandsId(param.getBrandsId());

        return null;
    }

    @Override
    public String findByBrandsId(FindByBrandsIdParam param) {
        return null;
    }
}
